import { createStore } from 'redux'
import rootReducer from './reducers/index'
// 导入持久化第三方库
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' // localeStorage 机制

const persistConfig = {
    key: 'root', 
    storage, 
    blacklist: ['loadingReducer'] // 只有 userInfo 不会被存在缓存
  };
 //persistReducer函数作用是把reducer按照上面配置(persistConfig)进行持久化
const persistedReducer = persistReducer(persistConfig, rootReducer)
 //把持久化的reducer传给createStore生成store
const store = createStore(persistedReducer);
//利用上面的store再使用persistStore生成一个持久化的stor
let persistor = persistStore(store)
export {
    // 普通store
    store,
    // 持久化store
    persistor
}